@echo off

set exe={exe}
set from={from}
set to={to}
set tmp={tmp}
set delay={delay}

set delaycount=0

echo exe= %exe%
echo from= %from%
echo to= %to%
echo delay= %delay%

if "%delay%" == "" goto begin

:delay
ping 127.0.0.1 -n 2 > nul
set /a delaycount+=1
if "%delaycount%"=="%delay%" goto begin
goto delay

:begin

if exist "%from%" (
    del /s /q "%to%"
    rename "%from%" "%to%"
    xcopy /E /Y /C /I "%from%" "%to%"
    del /s /q "%from%"
    del /s /q "%tmp%"
    
    echo "start application"
    start "" "%exe%"
    
    ping 127.0.0.1 >nul
    ping 127.0.0.1 >nul
    
    echo "finish"
    exit
) else (
    echo "Dir not exist: %from%"
)
